//
//  RJNavBar.m
//  AirQuality
//
//  Created by Po on 15/3/11.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJNavBar.h"
@interface RJNavBar ()

- (void)initData;
- (void)initInterface;
@end

@implementation RJNavBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initData];
        [self initInterface];
    }
    return self;
}

#pragma mark - user-defined initialization function
- (void)initData
{

}

- (void)initInterface
{
    //self init
    [self setFrame:CGRectMake(0,0,ScreenWidth,sysNavBarHeight)];
    [self setBackgroundColor:SysMainColor];
    
    //other UI
//    [self addSubview:[self getCenterTimeLabel]];
    [self addSubview:[self getCenterCityLabel]];
    [self addSubview:[self getRightButton]];
}


//- (UILabel *)getCenterTimeLabel
//{
//    if (!_centerTimeLabel) {
//        _centerTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/4, 35, ScreenWidth/2, 15)];
////        [_centerTimeLabel setCenter:CGPointMake(self.center.x, self.center.y + y)];
//        [_centerTimeLabel setTextAlignment:NSTextAlignmentCenter];
//        [_centerTimeLabel setTextColor:[UIColor whiteColor]];
//        [_centerTimeLabel setFont:[UIFont systemFontOfSize:12]];
//        [_centerTimeLabel setText:[self getNowTime]];
//    }
//    return _centerTimeLabel;
//}

- (UILabel *)getCenterCityLabel
{
    if (!_centerCityLabel) {
        _centerCityLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/4, 0, ScreenWidth/2, 50)];
        [_centerCityLabel setTextAlignment:NSTextAlignmentCenter];
        [_centerCityLabel setTextColor:[UIColor whiteColor]];
        [_centerCityLabel setFont:[UIFont systemFontOfSize:22]];
        NSString * title;
        if ([RJUserData defaultRJUserData].isProvince) {
            title = @"全省空气质量";
        } else {
            title = [RJUserData defaultRJUserData].currentCity;
        }
        [_centerCityLabel setText:title];
    }
    return _centerCityLabel;
}

- (UIButton *)getReturnButton
{
    if (!_returnButton) {
        _returnButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 8, 36, 46)];
        if (!_isOtherReturnButton) {
            _returnButton.frame = CGRectMake(10, 11, 63, 30);
            [_returnButton setTitle:@"返回" forState:0];
            _returnButton.titleLabel.font = [UIFont systemFontOfSize:16];
            _returnButton.layer.borderWidth = 2;
            _returnButton.layer.borderColor = GetRGBColor(27, 170, 169, 1).CGColor;
            _returnButton.layer.cornerRadius = 5;
        }
        _returnButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_returnButton addTarget:nil action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_returnButton];
    }
    return _returnButton;
}

- (UIButton *)getRightButton
{
    if (!_rightButton) {
        _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 60, 0, 60, 50)];
        [self addSubview:_rightButton];
    }
    return _rightButton;
}

#pragma mark - function
- (void)setReturnButtonHidden:(BOOL)isHidden
{
    [[self getReturnButton] setHidden:isHidden];
}

/**获取当前时间，并格式化*/
- (NSString *)getNowTime
{
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy年MM月dd日"];
    return [formatter stringFromDate:[NSDate date]];
}

- (void)setCenterLabelText:(NSString *)text
{
//    [[self getCenterTimeLabel] setText:text];
}









@end
